﻿<TabItem x:Class="FrontEnd.SQLQueryTab"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
		     xmlns:avalon="http://icsharpcode.net/sharpdevelop/avalonedit"
			 xmlns:fe="clr-namespace:FrontEnd"
			 DataContext="{Binding RelativeSource={RelativeSource Self}}">
	
	<TabItem.CommandBindings>
		<CommandBinding Command="fe:MyCommands.Execute" CanExecute="CanExecute" Executed="Execute" />
	</TabItem.CommandBindings>

	<TabItem.Resources>
		<SolidColorBrush x:Key="GridLineColour" Color="#F0F0F0" />
		<SolidColorBrush x:Key="QueryStatusBarBackground" Color="#F0E68C" />
	</TabItem.Resources>
	
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition />
			<RowDefinition Height="auto" />
			<RowDefinition />
			<RowDefinition Height="auto" />
		</Grid.RowDefinitions>
		<avalon:TextEditor Name="txtSQL" FontFamily="Consolas" FontSize="11pt" Padding="5" />
		<GridSplitter Grid.Row="1" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
		<DataGrid Name="grdResults" ItemsSource="{Binding LastResult.Data}" RowHeaderWidth="25" VerticalGridLinesBrush="{StaticResource GridLineColour}" HorizontalGridLinesBrush="{StaticResource GridLineColour}" Grid.Row="2" IsReadOnly="True" SelectionUnit="Cell" SelectionMode="Single" CanUserResizeRows="False">
			<DataGrid.Resources>
				<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#A8CEF5" />
			</DataGrid.Resources>
		</DataGrid>
		<StatusBar Grid.Row="3" Background="{StaticResource QueryStatusBarBackground}">
			<StatusBar.ItemsPanel>
				<ItemsPanelTemplate>
					<Grid>
						<Grid.ColumnDefinitions>
							<ColumnDefinition />
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="Auto" />
						</Grid.ColumnDefinitions>
					</Grid>
				</ItemsPanelTemplate>
			</StatusBar.ItemsPanel>
			<StatusBarItem>
				<TextBlock Name="lblQueryStatus" Text="..." />
			</StatusBarItem>
			<StatusBarItem Grid.Column="1">
				<TextBlock Name="lblQueryTime" Text="{Binding LastResult.TimeTaken.TotalMilliseconds, StringFormat={}{0:0.##} ms, FallbackValue=..., NotifyOnTargetUpdated=True}">
					<TextBlock.Triggers>
						<EventTrigger RoutedEvent="Binding.TargetUpdated" >
							<BeginStoryboard>
								<Storyboard>
									<DoubleAnimation AutoReverse="True" From="1.0" To="0.0" Duration="0:0:0.5" Storyboard.TargetProperty="(TextBlock.Opacity)" />
								</Storyboard>
							</BeginStoryboard>
						</EventTrigger>
					</TextBlock.Triggers>
				</TextBlock>
			</StatusBarItem>
			<Separator Grid.Column="2" />
			<StatusBarItem Grid.Column="3">
				<TextBlock Name="lblRowCount" Text="{Binding LastResult.Data.Rows.Count, StringFormat={}{0} rows, FallbackValue=0 rows, NotifyOnTargetUpdated=True}">
					<TextBlock.Triggers>
						<EventTrigger RoutedEvent="Binding.TargetUpdated" >
							<BeginStoryboard>
								<Storyboard>
									<DoubleAnimation AutoReverse="True" From="1.0" To="0.0" Duration="0:0:0.5" Storyboard.TargetProperty="(TextBlock.Opacity)" />
								</Storyboard>
							</BeginStoryboard>
						</EventTrigger>
					</TextBlock.Triggers>
				</TextBlock>
			</StatusBarItem>
		</StatusBar>
	</Grid>
</TabItem>
